<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>sstruct</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="http://openttd-python.googlecode.com">OpenTTD-Python</a></th>
          </tr></table></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        Module&nbsp;sstruct
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
    onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="sstruct-module.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<!-- ==================== MODULE DESCRIPTION ==================== -->
<h1 class="epydoc">Module sstruct</h1><p class="nomargin-top"><span class="codelink"><a href="sstruct-pysrc.html">source&nbsp;code</a></span></p>
<pre class="literalblock">
sstruct.py -- SuperStruct

Higher level layer on top of the struct module, enabling to 
bind names to struct elements. The interface is similar to 
struct, except the objects passed and returned are not tuples 
(or argument lists), but dictionaries or instances. 

Just like struct, we use format strings to describe a data 
structure, except we use one line per element. Lines are 
separated by newlines or semi-colons. Each line contains 
either one of the special struct characters ('@', '=', '&lt;', 
'&gt;' or '!') or a 'name:formatchar' combo (eg. 'myFloat:f'). 
Repetitions, like the struct module offers them are not useful 
in this context, except for fixed length strings  (eg. 'myInt:5h' 
is not allowed but 'myString:5s' is). The 'x' format character 
(pad byte) is treated as 'special', since it is by definition 
anonymous. Extra whitespace is allowed everywhere.

The sstruct module offers one feature that the &quot;normal&quot; struct
module doesn't: support for fixed point numbers. These are spelled
as &quot;n.mF&quot;, where n is the number of bits before the point, and m
the number of bits after the point. Fixed point numbers get 
converted to floats.

pack(format, object):
        'object' is either a dictionary or an instance (or actually
        anything that has a __dict__ attribute). If it is a dictionary, 
        its keys are used for names. If it is an instance, it's 
        attributes are used to grab struct elements from. Returns
        a string containing the data.

unpack(format, data, object=None)
        If 'object' is omitted (or None), a new dictionary will be 
        returned. If 'object' is a dictionary, it will be used to add 
        struct elements to. If it is an instance (or in fact anything
        that has a __dict__ attribute), an attribute will be added for 
        each struct element. In the latter two cases, 'object' itself 
        is returned.

unpack2(format, data, object=None)
        Convenience function. Same as unpack, except data may be longer 
        than needed. The returned value is a tuple: (object, leftoverdata).

calcsize(format)
        like struct.calcsize(), but uses our own format strings:
        it returns the size of the data in bytes.

</pre>

<hr />
<div class="fields">      <p><strong>Version:</strong>
        1.2
      </p>
      <p><strong>Copyright:</strong>
        Copyright 1998, Just van Rossum &lt;just@letterror.com&gt;
      </p>
</div><!-- ==================== CLASSES ==================== -->
<a name="section-Classes"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Classes</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-Classes"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="sstruct.error-class.html" class="summary-name">error</a>
    </td>
  </tr>
</table>
<!-- ==================== FUNCTIONS ==================== -->
<a name="section-Functions"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Functions</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-Functions"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="_test"></a><span class="summary-sig-name">_test</span>()</span></td>
          <td align="right" valign="top">
            <span class="codelink"><a href="sstruct-pysrc.html#_test">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="calcsize"></a><span class="summary-sig-name">calcsize</span>(<span class="summary-sig-arg">format</span>)</span></td>
          <td align="right" valign="top">
            <span class="codelink"><a href="sstruct-pysrc.html#calcsize">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="getformat"></a><span class="summary-sig-name">getformat</span>(<span class="summary-sig-arg">format</span>)</span></td>
          <td align="right" valign="top">
            <span class="codelink"><a href="sstruct-pysrc.html#getformat">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="pack"></a><span class="summary-sig-name">pack</span>(<span class="summary-sig-arg">format</span>,
        <span class="summary-sig-arg">object</span>)</span></td>
          <td align="right" valign="top">
            <span class="codelink"><a href="sstruct-pysrc.html#pack">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="unpack"></a><span class="summary-sig-name">unpack</span>(<span class="summary-sig-arg">format</span>,
        <span class="summary-sig-arg">data</span>,
        <span class="summary-sig-arg">object</span>=<span class="summary-sig-default">None</span>)</span></td>
          <td align="right" valign="top">
            <span class="codelink"><a href="sstruct-pysrc.html#unpack">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="unpack2"></a><span class="summary-sig-name">unpack2</span>(<span class="summary-sig-arg">format</span>,
        <span class="summary-sig-arg">data</span>,
        <span class="summary-sig-arg">object</span>=<span class="summary-sig-default">None</span>)</span></td>
          <td align="right" valign="top">
            <span class="codelink"><a href="sstruct-pysrc.html#unpack2">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
</table>
<!-- ==================== VARIABLES ==================== -->
<a name="section-Variables"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Variables</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-Variables"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="__package__"></a><span class="summary-name">__package__</span> = <code title="None">None</code>
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="sstruct-module.html#_elementRE" class="summary-name" onclick="show_private();">_elementRE</a> = <code title="re.compile(r'\s*([A-Za-z_][A-Za-z_0-9]*)\s*:\s*([cbBhHiIlLfd]|[0-9]+[p\
s]|([0-9]+)\.([0-9]+)(F))\s*(#.*)?$')">re.compile(r'\s<code class="re-op">*</code><code class="re-group">(</code><code class="re-group">[</code>A<code class="re-op">-</code>Za<code class="re-op">-</code>z_<code class="re-group">]</code><code class="re-group">[</code>A<code class="re-op">-</code>Za<code class="re-op">-</code>z_0<code class="re-op">-</code>9<code class="re-group">]</code><code class="re-op">*</code><code class="re-group">)</code>\s<code class="re-op">*</code>:\s<code class="re-op">*</code><code class="re-group">(</code><code class="re-group">[</code><code class="variable-ellipsis">...</code></code>
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="_emptyRE"></a><span class="summary-name">_emptyRE</span> = <code title="re.compile(r'\s*(#.*)?$')">re.compile(r'\s<code class="re-op">*</code><code class="re-group">(</code>#.<code class="re-op">*</code><code class="re-group">)</code><code class="re-op">?</code>$')</code>
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="_extraRE"></a><span class="summary-name">_extraRE</span> = <code title="re.compile(r'\s*([x@=&lt;&gt;!])\s*(#.*)?$')">re.compile(r'\s<code class="re-op">*</code><code class="re-group">(</code><code class="re-group">[</code>x@=&lt;&gt;!<code class="re-group">]</code><code class="re-group">)</code>\s<code class="re-op">*</code><code class="re-group">(</code>#.<code class="re-op">*</code><code class="re-group">)</code><code class="re-op">?</code>$')</code>
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="_fixedpointmappings"></a><span class="summary-name">_fixedpointmappings</span> = <code title="{8: 'b', 16: 'h', 32: 'l'}"><code class="variable-group">{</code>8<code class="variable-op">: </code><code class="variable-quote">'</code><code class="variable-string">b</code><code class="variable-quote">'</code><code class="variable-op">, </code>16<code class="variable-op">: </code><code class="variable-quote">'</code><code class="variable-string">h</code><code class="variable-quote">'</code><code class="variable-op">, </code>32<code class="variable-op">: </code><code class="variable-quote">'</code><code class="variable-string">l</code><code class="variable-quote">'</code><code class="variable-group">}</code></code>
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="_formatcache"></a><span class="summary-name">_formatcache</span> = <code title="{}"><code class="variable-group">{</code><code class="variable-group">}</code></code>
    </td>
  </tr>
</table>
<!-- ==================== VARIABLES DETAILS ==================== -->
<a name="section-VariablesDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Variables Details</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-VariablesDetails"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
</table>
<a name="_elementRE"></a>
<div class="private">
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">_elementRE</h3>
  
  <dl class="fields">
  </dl>
  <dl class="fields">
    <dt>Value:</dt>
      <dd><table><tr><td><pre class="variable">
re.compile(r'\s<code class="re-op">*</code><code class="re-group">(</code><code class="re-group">[</code>A<code class="re-op">-</code>Za<code class="re-op">-</code>z_<code class="re-group">]</code><code class="re-group">[</code>A<code class="re-op">-</code>Za<code class="re-op">-</code>z_0<code class="re-op">-</code>9<code class="re-group">]</code><code class="re-op">*</code><code class="re-group">)</code>\s<code class="re-op">*</code>:\s<code class="re-op">*</code><code class="re-group">(</code><code class="re-group">[</code>cbBhHiIlLfd<code class="re-group">]</code><code class="re-op">|</code><code class="re-group">[</code>0<code class="re-op">-</code>9<code class="re-group">]</code><code class="re-op">+</code><code class="re-group">[</code>p<span class="variable-linewrap"><img src="crarr.png" alt="\" /></span>
s<code class="re-group">]</code><code class="re-op">|</code><code class="re-group">(</code><code class="re-group">[</code>0<code class="re-op">-</code>9<code class="re-group">]</code><code class="re-op">+</code><code class="re-group">)</code>\.<code class="re-group">(</code><code class="re-group">[</code>0<code class="re-op">-</code>9<code class="re-group">]</code><code class="re-op">+</code><code class="re-group">)</code><code class="re-group">(</code>F<code class="re-group">)</code><code class="re-group">)</code>\s<code class="re-op">*</code><code class="re-group">(</code>#.<code class="re-op">*</code><code class="re-group">)</code><code class="re-op">?</code>$')
</pre></td></tr></table>
</dd>
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="http://openttd-python.googlecode.com">OpenTTD-Python</a></th>
          </tr></table></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Mon Oct 20 13:03:11 2008
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>
